/**
 * 
 */
jQuery(function($) {
	var index = parent.layer.getFrameIndex(window.name);
	
   	$("#update_id").click(function(){
   		var url=$(this).attr("url");
   		var t = $('#formName').serializeArray();
        console.log(JSON.stringify(t));
   		layer.load(2);
		$.post(
			url, 
			t,
		  	function(data){
		     if(data.success){
		     	layer.closeAll('loading');
		     	parent.layer.close(index);
		     	window.parent.location.reload(); //刷新父页面
		     }else{
		     	var json = JSON.stringify(data.msg);
		     	layer.closeAll('loading');
		     	layer.msg(json);
		     }
		 });
   	});
   	
   	$("#add_id").click(function(){
   		layer.load(2);
   		var url= $(this).attr("url");
        var t = $('#formName').serializeArray();
        console.log(JSON.stringify(t));
		$.post(
			url, 
			t,
		  	function(data){
		     if(data.success){
		     	layer.closeAll('loading');
		     	parent.layer.close(index);
		     	window.parent.location.reload(); //刷新父页面
		     }else{
		     	var json = JSON.stringify(data.msg);
		     	layer.msg(json);
		     	layer.closeAll('loading');
		     }
		});
   	});
   		
   $("#copy_id").click(function(){
	   var tempAmount=$("#cankao_amount_id").val();
	   var temp = $("#temp").val();
	   $("#temp").val((Number(temp)+1));
	   
	   $("#body_id").append('<tr>'+
		'<td>'+
		'	<div class="col-sm-12">'+
		'		<div class="input-group input-group-sm">'+
		'			<input type="text" readonly="true" class="form-control date-picker" '+
		'				name="list['+temp+'].workDate" data-date-format="yyyy-mm-dd"/>'+
		'			<span class="input-group-addon"><i class="icon-calendar"></i></span>'+
		'		</div>'+
		'	</div>'+
		'</td>'+
		'<td>'+
		'	<div class="input-daterange input-group">'+
		'		<div class="col-sm-6">'+
		'			<div class="input-group bootstrap-timepicker">'+
		'				<input type="text" name="list['+temp+'].startWorkTime" class="col-sm-12 startWorkTime" />'+
		'				<span class="input-group-addon">'+
		'					<i class="fa fa-clock-o bigger-110"></i>'+
		'				</span>'+
		'			</div>'+
		'		</div>'+
		'		<div class="col-sm-6">'+
		'			<div class="input-group bootstrap-timepicker">'+
		'				<input type="text" name="list['+temp+'].endWorkTime" class="col-sm-12 endWorkTime"/>'+
		'				<span class="input-group-addon">'+
		'					<i class="fa fa-clock-o bigger-110"></i>'+
		'				</span>'+
		'			</div>'+
		'		</div>'+
		'	</div>'+
		'</td>'+
		'<td>'+
		'<input type="text" value="'+tempAmount+
		'" AUTOCOMPLETE="off" name="list['+temp+'].paymentDO.pageAmount" class="col-sm-12" />'+
		'</td>'+
		'<td><input type="text" name="list['+temp+'].remark" class="col-sm-12" /></td>'+
		'<td>'+
		'	<a class="btn btn-minier btn-danger delete_id" href="javascript:void(0);" title="删除">'+
		'		<i class="icon-trash bigger-120"></i>'+
		'	</a>'+
		'</td>'+
		'<tr>');
   	});
   
   $("#cankao_amount_id").blur(function () {
	   if($("#orig_page_amount").val()=="") {
		   $("#orig_page_amount").val($("#cankao_amount_id").val());
	   }
	   
	   $("input[name$='pageAmount']").each(function(){
		   if($(this).val()=='') {
			   $(this).val($("#cankao_amount_id").val());
		   }
	   });
	   
	});
   	
   $("div").on("focus",".date-picker",function(){
	   	$(this).datepicker({
	   		language: 'zh-CN',//选择语言
			autoclose: true,
			todayHighlight: true,
			clearBtn:true
		})
   });
   
   $("#body_id").on("click",".delete_id",function(){
		$(this).parent().parent("tr").remove();
   });
   
   $("#return_id").click(function(){
		parent.layer.close(index);
   });
	
   //更新上班时间
   $("div").on("focus",".startWorkTime",function(){
	   $(this).timepicker({
		   	defaultTime:'09:00:00',
			minuteStep: 1,
			showSeconds: true,
			showMeridian: false,
			disableFocus: true,
			icons: {
				up: 'fa fa-chevron-up',
				down: 'fa fa-chevron-down'
			}
		}).on('focus', function() {
			$(this).timepicker('showWidget');
		}).next().on(ace.click_event, function(){
			$(this).prev().focus();
		});
	});
	
	//更新下班时间
	$("div").on("focus",".endWorkTime",function(){
	   $(this).timepicker({
		   defaultTime:'18:00:00',
		   minuteStep: 1,
		   showSeconds: true,
		   showMeridian: false,
		   disableFocus: true,
		   icons: {
			   up: 'fa fa-chevron-up',
			   down: 'fa fa-chevron-down'
		   }
		}).on('focus', function() {
			$(this).timepicker('showWidget');
		}).next().on(ace.click_event, function(){
			$(this).prev().focus();
		});
   });
   
});

